package com.cn.wanxi.servlet.back.news;

import com.cn.wanxi.model.NewsTypeModel;
import com.cn.wanxi.service.INewsTypeService;
import com.cn.wanxi.service.impl.NewsTypeServiceImpl;
import com.cn.wanxi.util.DataEncoding;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/back/news/type/add")
public class NewsTypeAddServlet extends HttpServlet {
    INewsTypeService newsTypeService = new NewsTypeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DataEncoding.setTextContentType(resp);
        DataEncoding.setCharacterEncoding(req,resp);
        NewsTypeModel newsType = new NewsTypeModel();
        newsType.setName(req.getParameter("name"));
        newsType.setHref(req.getParameter("href"));
        newsType.setCreate_time(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date().getTime()));
        int result = newsTypeService.addNewsType(newsType);
        resp.getWriter().print(result);
    }
}
